import { request } from './index.js'
// 小程序登录
export function getAddressData(){
	return request({
		url: "getRegionData",
	})
}

// 小程序登录
export function wxLogin(code){
	return request({
		url: "auth/onLogin",
		data: {
			code: code
		}
	})
}

// 新增或更新用户信息
export function updateUserInfo(data){
	return request({
		url: "auth/updateUserInfo",
		method: "post",
		data: data
	})
}

// 获取轮播图  轮播图位置：1发现推荐 2商城首页 3美学生活馆推荐  4分类推荐
export function getCarousel(type){
	return request({
		url: "getCarousel",
		method: "post",
		data: {
			position: type,
		}
	})
}

// 获取推荐的展会
export function getRecommendShow(page){
	return request({
		url: "art/getRecommendShow",
		method: "post",
		data: {
			page: page,
			per_page: 10
		}
	})
}

// 预约展会
export function appointShow(id, name, phone){
	return request({
		url: "art/appointShow",
		method: "post",
		data: {
			id: id,
			name: name,
			phone: phone
		}
	})
}

// 获取展会列表
export function getShowList(page, keywords, status){
	return request({
		url: "art/getShowList",
		method: "post",
		data: {
			page: page,
			rows: 10,
			keywords: keywords,
			time_status: status
		}
	})
}

// 获取展会详情
export function getShowInfo(id){
	return request({
		url: "art/getShowInfo",
		method: "post",
		data: {
			id: id,
		}
	})
}


// 获取商品分类
export function getGoodsCate(){
	return request({
		url: "goods/getGoodsCate",
		method: "post",
	})
}

// 获取商品列表
export function getGoodsList(page, keywords, cateId){
	return request({
		url: "goods/getGoodsList",
		method: "post",
		data: {
			page: page,
			rows: 10,
			keywords: keywords,
			cate_id: cateId
		}
	})
}

// 获取商品详情
export function getGoodsInfo(id){
	return request({
		url: "goods/getGoodsInfo",
		method: "post",
		data: {
			id: id,
		}
	})
}

// 获取推荐的商品
export function getRecommendGoods(page, row){
	return request({
		url: "goods/getRecommendGoods",
		method: "post",
		data: {
			page: page,
			per_page: row || 4
		}
	})
}

// 加入收藏
export function addCollect(id, type){
	return request({
		url: "user/addCollect",
		method: "post",
		data: {
			id: id,
			type: type
		}
	})
}

// 取消收藏
export function cancelCollect(id, type){
	return request({
		url: "user/cancelCollect",
		method: "post",
		data: {
			id: id,
			type: type
		}
	})
}

// 获取评论列表
export function getGoodsComment(id, page){
	return request({
		url: "goods/getGoodsComment",
		method: "post",
		data: {
			id: id,
			page: page,
			per_page: 10
		}
	})
}

// 加入购物车
export function addCart(id, number, type){
	return request({
		url: "cart/addCart",
		method: "post",
		data: {
			goods_id: id,
			goods_num: number,
			goods_type: type
		}
	})
}

// 购物车列表
export function getCartList(){
	return request({
		url: "cart/getCartList",
		method: "post",
	})
}

// 购物车加减数量
export function changeCartNumber(id, number){
	return request({
		url: "cart/changeCart",
		method: "post",
		data: {
			id: id,
			goods_num: number
		}
	})
}

// 删除购物车
export function delCart(id){
	return request({
		url: "cart/delCart",
		method: "post",
		data: {
			id: id,
		}
	})
}


// 订单结算|立即购买（备份验证后续数据）
export function accountOrder(goodsStr){
	return request({
		url: "order/accountOrder",
		method: "post",
		data: {
			goods: goodsStr
		}
	})
}

// 获取订单结算页（进入确认订单页计算运费等）
export function getAccountData(goodsStr, address, couponId){
	return request({
		url: "order/getAccountData",
		method: "post",
		data: {
			goods: goodsStr,
			address: address,
			user_coupon_id: couponId,
		}
	})
}

// 创建订单
export function createOrder(goodsStr, address, type, couponId){
	return request({
		url: "order/addOrder",
		method: "post",
		data: {
			goods: goodsStr,
			type: type,
			address: address,
			user_coupon_id: couponId
		}
	})
}

// 支付订单
export function payOrder(id,pay_source){
	return request({
		url: "order/payOrder",
		method: "post",
		data: {
			order_id: id,
			pay_source:1
		}
	})
}

// 订单列表
export function orderList(page, status, keywords){
	return request({
		url: "order/orderList",
		method: "post",
		data: {
			page: page,
			per_page: 10,
			order_status: status,
			keywords: keywords
		}
	})
}

// 订单详情
export function orderInfo(id){
	return request({
		url: "order/orderInfo",
		method: "post",
		data: {
			order_id: id
		}
	})
}

// 取消订单
export function cancelOrder(id){
	return request({
		url: "order/cancelOrder",
		method: "post",
		data: {
			order_id: id
		}
	})
}

// 删除订单
export function delOrder(id){
	return request({
		url: "order/delOrder",
		method: "post",
		data: {
			order_id: id
		}
	})
}

// 申请退款
export function refundOrder(id){
	return request({
		url: "order/refundOrder",
		method: "post",
		data: {
			order_id: id
		}
	})
}

// 确认收货
export function confirmOrder(id){
	return request({
		url: "order/confirmOrder",
		method: "post",
		data: {
			order_id: id
		}
	})
}

// 物流查询
export function searchLogistics(id){
	return request({
		url: "order/searchLogistics",
		method: "post",
		data: {
			order_id: id
		}
	})
}



// 收货地址列表
export function addressList(){
	return request({
		url: "user/addressList",
		method: "post",
		data: {
			page: 1,
			per_page: 30,
		}
	})
}

// 收货地址详情
export function addressDetail(id){
	return request({
		url: "user/getAddress",
		method: "post",
		data: {
			id: id
		}
	})
}

// 删除收货地址
export function delAddress(id){
	return request({
		url: "user/delAddress",
		method: "post",
		data: {
			id: id
		}
	})
}

// 新增收货地址
export function addAddress(name, phone, province, city, district, area, address, is_default){
	return request({
		url: "user/addAddress",
		method: "post",
		data: {
			name: name,
			phone: phone,
			province: province,
			city: city,
			district: district,
			area: area,
			address: address,
			is_default: is_default,
		}
	})
}

// 编辑收货地址
export function editAddress(id, name, phone, province, city, district, area, address, is_default){
	return request({
		url: "user/editAddress",
		method: "post",
		data: {
			id: id,
			name: name,
			phone: phone,
			province: province,
			city: city,
			district: district,
			area: area,
			address: address,
			is_default: is_default,
		}
	})
}

// 获取用户信息
export function userInfo(){
	return request({
		url: "user/getUserInfo",
		method: "post",
	})
}

// 获取用户收藏列表
export function userCollectList(page, type){
	return request({
		url: "user/getUserCollectList",
		method: "post",
		data: {
			page: page,
			per_page: 10,
			type: type
		}
	})
}

// 获取用户预约列表
export function userAppointList(type, page){
	return request({
		url: "user/getUserAppointList",
		method: "post",
		data: {
			page: page,
			per_page: 10,
			type: type
		}
	})
}

// 艺术品
// 获取主体列表
export function mainList(type){
	return request({
		url: "art/getMainList",
		method: "post",
		data: {
			type: type  //1拉胚器 2注塑器
		}
	})
}

// 获取配件列表
export function partsList(){
	return request({
		url: "art/getPartsList",
		method: "post",
	})
}

// 通过配件获取主体
export function mainByParts(id){
	return request({
		url: "art/getMainByParts",
		method: "post",
		data: {
			part_id: id  
		}
	})
}

// 获取艺术品列表
export function artList(page, keywords){
	return request({
		url: "art/getArtList",
		method: "post",
		data: {
			page: page,
			per_page: 10,
			keywords: keywords
		}
	})
}

// 获取艺术品详情
export function artDetail(id){
	return request({
		url: "art/getArtDetail",
		method: "post",
		data: {
			art_id: id
		}
	})
}

// 获取主体详情
export function getMainDetail(id){
	return request({
		url: "art/getMainDetail",
		method: "post",
		data: {
			id: id
		}
	})
}

// 获取配件详情
export function getPartsDetail(id){
	return request({
		url: "art/getPartsDetail",
		method: "post",
		data: {
			id: id
		}
	})
}


// 获取贴花详情
export function getAppliqueDetail(id){
	return request({
		url: "art/getAppliqueDetail",
		method: "post",
		data: {
			id: id
		}
	})
}

// 获取用户贴花列表
export function getUserApplique(){
	return request({
		url: "art/getUserApplique",
		method: "post"
	})
}

// 删除用户贴花
export function delUserApplique(id){
	return request({
		url: "art/delUserApplique",
		method: "post",
		data: {
			id: id
		}
	})
}

// 获取优惠券列表
export function couponList(page,code){
	return request({
		url: "coupon/getCouponList",
		method: "post",
		data: {
			code:code,
			page: page,
			per_page: 20
		}
	})
}

// 获取用户优惠券
export function userCoupon(page, status){
	return request({
		url: "coupon/getUserCoupon",
		method: "post",
		data: {
			page: page,
			per_page: 20,
			status: status
		}
	})
}

// 获取可用的优惠券
export function usableCoupon(amount){
	return request({
		url: "coupon/getUsableCoupon",
		method: "post",
		data: {
			page: 1,
			per_page: 100,
			amount: amount
		}
	})
}

// 领取优惠券
export function receiveCoupon(id){
	return request({
		url: "coupon/receiveCoupon",
		method: "post",
		data: {
			id: id
		}
	})
}

// 可开票订单
export function invoiceOrderList(page){
	return request({
		url: "invoice/orderList",
		method: "post",
		data: {
			page: page,
			per_page: 10
		}
	})
}

// 开票
export function openInvoice(type, head, name, tax_num, register_address, register_phone, bank, account, email, order){
	return request({
		url: "invoice/openInvoice",
		method: "post",
		data: {
			type: type,
			head: head,
			name: name,
			tax_num: tax_num,
			register_address: register_address,
			register_phone: register_phone,
			bank: bank,
			account: account,
			email: email,
			order: order
		}
	})
}
